package org.FaPe3D.utils
{
	import com.adobe.serialization.json.*;
	
	import org.papervision3d.core.math.Number3D;
	public class PathList
	{		
		private var _list:Array = new Array();
		
		public function PathList(path:String = null)
		{
			if(path != null)
			{
				var arr:Array = JSON.decode(  path ) as Array;
				
				var position:Number3D;
				var rotation:Number3D;
				var speed:Number;
				for(var i:uint=0; i<arr.length; i++)
				{
					position = new Number3D( checkValue(arr[i].x), checkValue(arr[i].y), checkValue(arr[i].z));
					rotation = new Number3D( checkValue(arr[i].rotationX), checkValue(arr[i].rotationY), checkValue(arr[i].rotationZ));
					speed = checkValue( arr[i].speed, 0 );
					add(new CameraPath( position, rotation, speed));
				}
			}
		}
		
		public function checkValue(value:*, ret:*=null):Number
		{
			var i:Number;
			
			if(value != undefined)
			{
				i = Number( value )	
			}else
			{
				i = ret;
			}
			
			return i;
		}
		
		public function add(path:CameraPath)
		{
			_list.push( path );
		}
		
		public function getByIndex(index:Number):CameraPath
		{
			return _list[index];
		}
		
		public function get length():Number
		{
			return _list.length;	
		}
		
		public function toString(): String
		{
			var ret:String = '';
			
			for(var i:uint=0; i<_list.length; i++)
			{
				ret += _list[i].toString() + ' , ';
			}
			
			return ret;
		}
		
		
	}
}